int latchPin = 8; //ST_CP 低電位鎖定資料並輸出Q0~Q7;高電位更新
int clockPin = 12; //SH_CP
int dataPin = 11; //DATA
int index = 0;            // 七段顯示器的數字索引

const byte LED_A[10] = {  // 記錄0~9的七段數字
0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8,0x80,0x90,
};

const byte LED_B[10] = {  // 記錄9~0的七段數字
  B01110011,
  B01111111,
  B01110000,
  B01011111,
  B01011011,
  B00110011,
  B01111001,
  B01101101,
  B00110000,
  B01111110
};
void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  digitalWrite(latchPin, LOW);   // 關上閘門
  // 先推入「陣列B」
  shiftOut(dataPin, clockPin, LSBFIRST,0xff);
  // 再推入「陣列A」
  shiftOut(dataPin, clockPin, MSBFIRST, LED_A[index]);
  digitalWrite(latchPin, HIGH);  // 開啟閘門
  delay(1000);       // 暫停一秒
  index ++;
  if (index == 10) {
    index = 0;
  }
}
